package com.fast.develop.configuration.properties;

import cn.hutool.core.util.StrUtil;
import com.fast.develop.core.properties.DomainRuntimeProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

/**
 * @author 莫寅
 * @createTime 2022-06-06 11:34
 * @desc：
 */
@ConfigurationProperties(prefix = "fast.develop")
public class FastDevelopPropesties {

    @NestedConfigurationProperty
    private DomainRuntimeProperties domain = new DomainRuntimeProperties();

    private String editorWebUrl;

    private boolean enablePrint = false;

    private boolean openBrowser = false;

    /**
     * 运行模式
     */
    private RuntimeMode runtimeMode = RuntimeMode.FILE;

    public DomainRuntimeProperties getDomain() {
        return domain;
    }

    public void setDomain(DomainRuntimeProperties domain) {
        this.domain = domain;
    }

    public boolean isEnablePrint() {
        return enablePrint;
    }

    public void setEnablePrint(boolean enablePrint) {
        this.enablePrint = enablePrint;
    }

    public boolean isOpenBrowser() {
        return openBrowser;
    }

    public void setOpenBrowser(boolean openBrowser) {
        this.openBrowser = openBrowser;
    }

    public RuntimeMode getRuntimeMode() {
        return runtimeMode;
    }

    public void setRuntimeMode(RuntimeMode runtimeMode) {
        this.runtimeMode = runtimeMode;
    }

    public String getEditorWebUrl() {
        if (StrUtil.isBlank(editorWebUrl)) {
            return "";
        }
        if (editorWebUrl.endsWith("/**")) {
            return editorWebUrl.substring(0, editorWebUrl.length() - 3);
        }
        if (editorWebUrl.endsWith("/*")) {
            return editorWebUrl.substring(0, editorWebUrl.length() - 2);
        }
        if (editorWebUrl.endsWith("/")) {
            return editorWebUrl.substring(0, editorWebUrl.length() - 1);
        }
        return editorWebUrl;
    }

    public void setEditorWebUrl(String editorWebUrl) {
        this.editorWebUrl = editorWebUrl;
    }

    public enum RuntimeMode{
        FILE,MEMORY,DATABASE
    }
}
